﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;

namespace LightSwitchApplication
{
    public partial class Product
    {
        partial void RecipeDependenciesList_Compute(ref string result)
        {
            string dependenciesNames = string.Empty;
            if (this.RecipeDependencies != null && this.ProductGroup != null && this.ProductGroup.ParentProductGroup != null)
            {
                foreach (var parentDependency in this.RecipeDependencies)
                {
                    if (parentDependency != null && parentDependency.ParentRecipeProduct != null )
                        dependenciesNames += (dependenciesNames == string.Empty ? string.Empty : "; ") + parentDependency.ParentRecipeProduct.ProductGroup.ProductGroupName + ": "+ parentDependency.ParentRecipeProduct.ProductName;
                }
            }
            result = dependenciesNames;

        }

        partial void ProductImage_Validate(EntityValidationResultsBuilder results)
        {
            int sizeInKB;
            if (ProductImage != null)
            {
                sizeInKB = ProductImage.Length / 1024;

                if (sizeInKB > 512)
                {
                    results.AddPropertyError(Messages.FileSizeToBig);
                }
            }
        }
    }
}
